package day12;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class TalkClient {
    public static void main(String[] args) {
        Socket s=null;
        try {
             s=new Socket("localhost",9996);
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            PrintWriter pw = new PrintWriter(out, true);
            Scanner sc=new Scanner(System.in);
            String str=null;
            while (true){
                System.out.println("问吧：");
                str=sc.next();
                pw.println(str);
                String reply=br.readLine();
                System.out.println("服务器说："+reply);
                if(str.equals("byebye"))
                    break;
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(s!=null) {
                try {
                    s.close();
                } catch (Exception e) {

                }
            }
        }
    }
}
